package com.niiwoo.civet.trade.dao.mapper;

import com.niiwoo.civet.trade.dao.entity.ProjectBorrowerPlanDetail;
import com.niiwoo.civet.trade.dto.BorrowerPlanDetailDTO;
import com.niiwoo.civet.trade.dto.ProjectBorrowerAmountSumDTO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Component
public interface ProjectBorrowerPlanDetailMapperExt extends ProjectBorrowerPlanDetailMapper{
    ProjectBorrowerPlanDetail selectByPrimaryKeyForUpdate(Long id);

    /**
     * 根据还款计划ID和费用类型查询还款金额明细
     *
     * @param planId
     * @param feeType
     * @return
     */
    ProjectBorrowerPlanDetail queryProjectBorrowerPlanDetailByPlanIdAndFeeType(@Param("planId") Long planId, @Param("feeType") Integer feeType);

    /**
     * 查询已收总罚息
     * @param projectId
     * @return
     */
    BigDecimal queryRefunedPenalty(@Param("projectId") Long projectId);

    /**
     * 根据标的ID查询待还计划
     * @param projectId
     * @return
     */
    List<BorrowerPlanDetailDTO> queryNotReceiveDetailsByProjectId(@Param("projectId") Long projectId);

    /**
     * 根据标的ID,当前期数查询待还计划
     * @param projectId
     * @param period
     * @return
     */
    List<BorrowerPlanDetailDTO> queryNotReceiveDetailsByProjectIdCurrentPeriod(@Param("projectId") Long projectId, @Param("period") Integer period);

    /**
     * 根据标的ID,还款日查询待还计划
     * @param projectId
     * @param refundDate
     * @return
     */
    List<BorrowerPlanDetailDTO> queryNotReceiveDetailsByProjectIdRefundDate(@Param("projectId") Long projectId, @Param("refundDate") Date refundDate);

    /**
     * 查询还款计划明细
     * @param planId
     * @return
     */
	List<ProjectBorrowerPlanDetail> selectByPlanId(@Param("planId") Long planId);

    /**
     * 据标的号查询明细
     */
    List<ProjectBorrowerPlanDetail> selectByProjectId(@Param("projectId") Long projectId);

    /**
     * 查询正常还款应还总金额(不含罚息)
     */
    BigDecimal selectTotalAmountByProjectId(@Param("projectId") Long projectId);

    /**
     * 据标的号查询罚息明细
     */
    List<ProjectBorrowerPlanDetail> selectPenaltyDetailByProjectId(@Param("projectId") Long projectId);

    /**
     * 根据还款计款ID列表查询还款计划详情
     * 
     * @param planIdList
     * @return
     */
    List<ProjectBorrowerPlanDetail> selectListByPlanIds(@Param("list") List<Long> planIdList);



    List<ProjectBorrowerPlanDetail> selectListByPlanIdsFeeType(@Param("list") List<Long> planIdList, @Param("feeType") Integer feeType);
    
    /**
     * 根据用户ID和费用类型统计待还金额
     * 
     * @param userId
     * @return
     */
    BigDecimal countToPayMoneyByUserIdAndFeeType(@Param("userId") String userId, @Param("feeType") Integer feeType);

    /**
     * 根据标的ID和费用类型统计该项总费用
     * @param projectId
     * @param feeType
     * @return
     */
    BigDecimal countTotalMoneyByProjectIdAndFeeType(@Param("projectId") Long projectId, @Param("feeType") Integer feeType);

    /**
     * 查询当前还款后的待还款本金
     * 
     * @param projectId
     * @param currentPeriod
     * @param feeType
     * @return
     */
    BigDecimal countUnfinishedAmountForFeeType(@Param("projectId") Long projectId, @Param("currentPeriod") Integer currentPeriod, @Param("feeType") Integer feeType);

    /**
     * 查询总利息
     */
    BigDecimal selectTotalInterestByProjectId(@Param("projectId")Long projectId);

    BigDecimal countToPayMoneyByProjectIdAndFeeType(@Param("projectId") Long projectId, @Param("feeType") Integer feeType);

    BigDecimal selectCapitalAndInterestToRefundOverdue(@Param("projectId") Long projectId,@Param("compareDate")Date compareDate);

}